<?php

/**
 * @author Kevin
 * @version 1.0
 * @created 12-d�c.-2011 19:51:40
 */
class Comment extends Publication implements I_Reportable
{

	var $comment;
	var $referedTo;


	/**
	 * 
	 * @param pId
	 */
	function Comment($id = 0)
	{
		parent::Publication("COMMENT", $id);
		
		global $wpdb;
		$_row = $wpdb->get_row($wpdb->prepare("SELECT * FROM comments WHERE id = %d", $id));
		
		if($_row->id > 0){
			$this->comment = $_row->comment;
			$this->referedTo = $_row->fk_publicationid;
		}
		
		
	}

	/**
	 * Enter description here ...
	 */
	function create()
	{
		global $wpdb;
			
		$queryTable = 'comments';
		$queryData = array(			 
			'fk_publicationid' => $this->referedTo,
			'comment' => $this->comment
		);
		$queryDataFormat = array('%d','%s');
		
		$wpdb->insert( $queryTable, $queryData, $queryDataFormat);
		
		$this->id = $wpdb->insert_id;
		
		parent::setId($this->getId());
		parent::create();
	}

	function delete()
	{
		
	}

	function getComment()
	{
		return $this->comment;
	}

	function getReference()
	{
		return $this->referedTo;
	}

	function report()
	{
	}

	/**
	 * Enter description here ...
	 */
	function save()
	{
	}

	/**
	 * 
	 * @param comment
	 */
	function setComment($comment)
	{
		$this->comment = $comment;
	}

	/**
	 * 
	 * @param referTo
	 */
	function setReference($referTo)
	{
		$this->referedTo = $referTo;
	}

	/**
	 * Enter description here ...
	 */
	function toHTML()
	{
		$_owner = $this->getOwner();
		?>
		<div class="div_comment">
			<div class="div_userPicture">
				<img src="http://localhost/weebeet.com/wp-content/themes/toolbox/style/generic/images/users/default.png">
			</div>
			<div class="div_content">
				<a href="?profile=<?php echo $_owner->getId(); ?>" class="userNickname"><?php echo $_owner->getNickname(); ?></a> - 
				<span class="c_9"><?php echo $this->getDate(). " à " . $this->getHour(); ?></span> - 
				<?php echo $this->getComment(); ?>
			</div>
			<div class="div_action">
				<span class="fl action tiptip icon_20 deletePublication cursor" action="deleteComment" commentID='<?php echo $this->getId(); ?>'></span>
				<span class="fl action tiptip icon_20 signalPublication cursor" action="signalComment" commentID='<?php echo $this->getId(); ?>'></span>
			</div>
		</div>
		<?php
	}

}
?>